﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class SystemManager_websiteinfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //读取数据内容
            EntityOprHelper helper = new EntityOprHelper();
            T_WEBSITEINFO webinfo = helper.GetEntityByWhere<T_WEBSITEINFO>(" WHERE ID>=0 ORDER BY ID DESC");

            if (webinfo!=null)
            {
                webnametext.Text = webinfo.title;
                webkeywordstext.Text = webinfo.keywords;
                webctiontext.Text = webinfo.description;
                webCopyrighttext.Text = webinfo.copyright;
                recordid.Text = webinfo.ID.ToString();
            }
        }
        else
        { 
            //保存数据内容

        }
    }
    protected void Submit_Click(object sender, EventArgs e)
    {

         String title=webnametext.Text ;
         String keywords = webkeywordstext.Text;
         String description = webctiontext.Text;
         String copyright = webCopyrighttext.Text;
         String webID = recordid.Text;
         if (title == "" && keywords == "" && description == "" && copyright == "")
         {
             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('您没有输入任何信息!')", true);
             return;
         }
         if (webID == "")
         {
                //添加信息
                 EntityOprHelper helper = new EntityOprHelper();
                 T_WEBSITEINFO webinfo = new T_WEBSITEINFO();
                 webinfo.copyright = copyright;
                 webinfo.title = title;
                 webinfo.description = description;
                 webinfo.keywords = keywords;
                 bool b = helper.AddEntity<T_WEBSITEINFO>(webinfo);
                 if (b)
                 {
                     ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改成功!')", true);
                 }
                 else
                 {
                     ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改失败!')", true);
                 }
         }
         else
         { 
                //修改信息
             EntityOprHelper helper = new EntityOprHelper();
             T_WEBSITEINFO webinfo = new T_WEBSITEINFO();
             webinfo.copyright = copyright;
             webinfo.title = title;
             webinfo.description = description;
             webinfo.keywords = keywords;
             webinfo.ID = Convert.ToInt16(webID);
             bool b= helper.EditEntity<T_WEBSITEINFO>(webinfo);
             if (b)
             {
                 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改成功!')", true);
             }
             else
             {
                 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改失败!')", true);
             }

         }
    }
}
